package br.com.requisicao.compra.dao.impl;

import org.hibernate.Session;
import org.hibernate.Transaction;

import br.com.requisicao.compra.dao.DAOFactory;
import br.com.requisicao.compra.util.HibernateUtil;


public class HibernateDAOFactory extends DAOFactory {
	private Session session;
	private Transaction tx;

	public HibernateDAOFactory() {
		this.session = HibernateUtil.getSession();
	}

	@Override
	public void cancelarTransacao() {
		this.tx.rollback();
		this.tx = null;
	}

	@Override
	public void iniciarTransacao() {
		this.tx = this.session.beginTransaction();
	}

	@Override
	public void encerrar() {
		if (this.tx != null) {
			this.tx.commit();
		}
		this.session.close();
	}

}
